package com.element5th.shop.servlet.good;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.element5th.shop.dao.good.GoodDaoImpl;
import com.element5th.shop.dao.good.IGoodDao;
import com.element5th.shop.dto.BaseDto;

/**
 * Servlet implementation class GetRecommendGood
 */
@WebServlet("/GetRecommendGood")
public class GetRecommendGood extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public GetRecommendGood() {
		super();
	}

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		IGoodDao dao = new GoodDaoImpl();
		List<BaseDto> dtoList = new ArrayList<BaseDto>();

		dtoList = dao.getRecommendGood();

		PrintWriter writer = response.getWriter();

		for (int i = 0; i < dtoList.size(); i++) {

			writer.print("<li class='good_li'><a class='good_a_pic' href=''><img src='images/goodPic/toppic/"
					+ dtoList.get(i).getGoodDetail().getDetailToppic()
					+ "'/> </a> <a class='good_a_text' href=''>"
					+ dtoList.get(i).getGoodDetail().getDetailTitle()
					+ "</a><div class='div_price'><span class='div_price_s'>五折价:</span> <span class='good_price'>￥"
					+ dtoList.get(i).getShopGood().getGoodPrice()
					+ "</span></div></li>");

		}
	}
}
